from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.endpoints import questions  # Import the questions router
from app.core.config import settings
from app.db import base_class  # Changed from base to base_class
from app.db.database import engine # Import engine from MySQL setup

# Create database tables 
# This should ideally be handled by Alembic migrations in a production app
base_class.Base.metadata.create_all(bind=engine)

app = FastAPI(
    title=settings.PROJECT_NAME,
    version="1.0.0",
    openapi_url=f"{settings.API_V1_STR}/openapi.json"
)

# CORS تەڭشەش
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# يول قوشۇش
app.include_router(questions.router, prefix=settings.API_V1_STR + "/questions", tags=["questions"])

@app.get("/")
def read_root():
    return {"message": "Welcome to the Questions API"}

# Add any other routers or middleware here

# Example: If you have other endpoints in a different router
# from app.api.endpoints import other_router
# app.include_router(other_router.router, prefix=settings.API_V1_STR + "/others", tags=["others"])

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)